<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="账户名" prop="account">
        <el-input
          v-model="queryParams.account"
          placeholder="请输入账户名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input
          v-model="queryParams.password"
          placeholder="请输入密码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信标识" prop="weixin">
        <el-input
          v-model="queryParams.weixin"
          placeholder="请输入微信标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="qq标识" prop="qq">
        <el-input
          v-model="queryParams.qq"
          placeholder="请输入qq标识"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="性别" prop="gender">
        <el-input
          v-model="queryParams.gender"
          placeholder="请输入性别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="位置" prop="position">
        <el-input
          v-model="queryParams.position"
          placeholder="请输入位置"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="简介" prop="profile">
        <el-input
          v-model="queryParams.profile"
          placeholder="请输入简介"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option
            v-for="dict in dict.type.sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="登录时间" prop="loginDate">
        <el-date-picker clearable
          v-model="queryParams.loginDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择登录时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="big" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="big" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="big"
          @click="handleAdd"
          v-hasPermi="['system:fhUser:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="big"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:fhUser:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="big"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:fhUser:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="big"
          @click="handleExport"
          v-hasPermi="['system:fhUser:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="fhUserList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="账户名" align="center" prop="account" />
      <el-table-column label="密码" align="center" prop="password" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="微信标识" align="center" prop="weixin" />
      <el-table-column label="qq标识" align="center" prop="qq" />
      <!-- <el-table-column label="头像" align="center" prop="image" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.image" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="name" /> -->
      <el-table-column label="性别" align="center" prop="gender" />
      <!-- <el-table-column label="位置" align="center" prop="position" />
      <el-table-column label="简介" align="center" prop="profile" />
      <el-table-column label="邮箱" align="center" prop="email" /> -->
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="登录时间" align="center" prop="loginDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.loginDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="300">
        <template slot-scope="scope">
          <el-button
            size="big"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdateInfo(scope.row)"
            v-hasPermi="['info:user:edit']"
          >详情</el-button>
          <el-button
            size="big"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:fhUser:edit']"
          >修改</el-button>
          <el-button
            size="big"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:fhUser:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户控制对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="账户名" prop="account">
          <el-input v-model="form.account" placeholder="请输入账户名" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="form.password" placeholder="请输入密码" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="微信标识" prop="weixin">
          <el-input v-model="form.weixin" placeholder="请输入微信标识" />
        </el-form-item>
        <el-form-item label="qq标识" prop="qq">
          <el-input v-model="form.qq" placeholder="请输入qq标识" />
        </el-form-item>
        <!-- <el-form-item label="头像" prop="image">
          <image-upload v-model="form.image"/>
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item> -->
        <el-form-item label="性别" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入性别" />
        </el-form-item>
        <!-- <el-form-item label="位置" prop="position">
          <el-input v-model="form.position" placeholder="请输入位置" />
        </el-form-item>
        <el-form-item label="简介" prop="profile">
          <el-input v-model="form.profile" placeholder="请输入简介" />
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入邮箱" />
        </el-form-item> -->
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.sys_normal_disable"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="登录时间" prop="loginDate">
          <el-date-picker clearable
            v-model="form.loginDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择登录时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 添加或修改用户信息对话框 -->
    <el-dialog :title="title" :visible.sync="openInfo" width="500px" append-to-body>
      <el-form ref="formInfo" :model="formInfo" :rules="rules" label-width="80px">
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="formInfo.userId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="formInfo.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="图片" prop="image">
          <image-upload v-model="formInfo.image"/>
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-input v-model="formInfo.gender" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="formInfo.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="钓鱼水平" prop="level">
          <el-input v-model="formInfo.level" placeholder="请输入钓鱼水平" />
        </el-form-item>
        <el-form-item label="等级" prop="grade">
          <el-input v-model="formInfo.grade" placeholder="请输入等级" />
        </el-form-item>
        <el-form-item label="经验" prop="experience">
          <el-input v-model="formInfo.experience" placeholder="请输入经验" />
        </el-form-item>
        <el-form-item label="关注数" prop="followers">
          <el-input v-model="formInfo.followers" placeholder="请输入关注数" />
        </el-form-item>
        <el-form-item label="粉丝数" prop="fans">
          <el-input v-model="formInfo.fans" placeholder="请输入粉丝数" />
        </el-form-item>
        <el-form-item label="积分" prop="points">
          <el-input v-model="formInfo.points" placeholder="请输入积分" />
        </el-form-item>
        <el-form-item label="金币" prop="coins">
          <el-input v-model="formInfo.coins" placeholder="请输入金币" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="formInfo.address" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="个人简介" prop="profile">
          <el-input v-model="formInfo.profile" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="邮箱地址" prop="email">
          <el-input v-model="formInfo.email" placeholder="请输入邮箱地址" />
        </el-form-item>
        <el-form-item label="兴趣点" prop="interests">
          <el-input v-model="form.interests" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="formInfo.status">
            <el-radio
              v-for="dict in dict.type.sys_normal_disable"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="创建时间" prop="crateTime">
          <el-date-picker clearable
            v-model="formInfo.crateTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
//用户账号Api
import { listFhUser, getFhUser, delFhUser, addFhUser, updateFhUser } from "@/api/system/fhUser";
//用户信息Api
import { listUser, getUser,getUserByUserId, delUser, addUser, updateUser } from "@/api/info/user";

export default {
  name: "FhUser",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户控制表格数据
      fhUserList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示用户详情
      openInfo: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        account: null,
        password: null,
        phone: null,
        weixin: null,
        qq: null,
        image: null,
        name: null,
        gender: null,
        position: null,
        profile: null,
        email: null,
        status: null,
        loginDate: null
      },
      // 表单参数
      form: {},
      // 信息表单参数
      formInfo: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户控制列表 */
    getList() {
      this.loading = true;
      listFhUser(this.queryParams).then(response => {
        this.fhUserList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        account: null,
        password: null,
        phone: null,
        weixin: null,
        qq: null,
        image: null,
        name: null,
        gender: null,
        position: null,
        profile: null,
        email: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        loginDate: null
      };
      this.resetForm("form");
    },
    // 信息表单重置
    resetInfo() {
      this.formInfo = {
        id: null,
        userId: null,
        phone: null,
        image: null,
        gender: null,
        name: null,
        level: null,
        grade: null,
        experience: null,
        followers: null,
        fans: null,
        points: null,
        coins: null,
        address: null,
        profile: null,
        email: null,
        interests: null,
        status: null,
        createBy: null,
        crateTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("formInfo");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户控制";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFhUser(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户控制";
      });
    },
     /** 详情按钮操作 */
     handleUpdateInfo(row) {
      this.resetInfo();
      const id = row.id || this.ids
      getUserByUserId(id).then(response => {
        this.formInfo = response.data;
        this.openInfo = true;
        this.title = "用户详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFhUser(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFhUser(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除用户控制编号为"' + ids + '"的数据项？').then(function() {
        return delFhUser(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/fhUser/export', {
        ...this.queryParams
      }, `fhUser_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
